package com.flyou.ccnucenter.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.flyou.ccnucenter.utils.BitmapUtil;
import com.flyou.ccnucenter.widget.photoview.PhotoView;
import com.flyou.photopicker.model.PhotoInfo;

import java.util.ArrayList;

/**
 * ============================================================
 * 项目名称：ChildDevelopmentAssistant
 * 包名称：com.e1858.childassistant.adapter
 * 文件名：LostFoundPsotPhotoAdapter
 * 类描述：
 * 创建人：flyou
 * 邮箱：fangjaylong@gmail.com
 * 创建时间：2015/12/11 12:59
 * 修改备注：
 * 版本：@version  V1.0
 * ============================================================
 */
public class LostFoundGalleryPhotoAdapter extends PagerAdapter {
    private ArrayList<PhotoInfo> photos;
    private Context context;

    public LostFoundGalleryPhotoAdapter(Context context, ArrayList<PhotoInfo> photos) {
        this.photos = photos;
        this.context=context;
    }


    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        return arg0 == arg1;
    }

    @Override
    public int getCount() {
        return photos.size();
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        ImageView view = (ImageView) object;
        container.removeView(view);
    }
    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        PhotoInfo photoInfo = photos.get(position);
        PhotoView imageView = new PhotoView(context);
        imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
        imageView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        try {
            if (null==photoInfo.getPhotoPath()){
                return null;
            }
            Bitmap bitmap = BitmapUtil.revitionImageSize(photoInfo.getPhotoPath());
            imageView.setImageBitmap(bitmap);
            container.addView(imageView);
        } catch (Exception e) {
            e.printStackTrace();
        }



        return imageView;
    }
}


